# !/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :testCase.py
# @Time      :2022/7/12 0:56
# @Author    :jiaxuesong

import requests
import unittest
from ddt import ddt,unpack,data
from Review_test.interface03.common.readExcle import *
from Review_test.interface03.common.configHttp import *
from Review_test.interface03.common.writeExcle import *


#调用实例方法获取测试数据
data_obj = ReadExcle()
test_data = data_obj.read()
#创建用例，定义一个测试类
#使用ddt装饰器，对每条用例进行调用
@ddt
class TestCase(unittest.TestCase):
    #创建测试用例方法
    @data(*test_data)
    @unpack
    def test_case(self, id, interfaceUrl, name, method, value, expect, real, status):
        # 实例化confighttp类，进行调用
        value = eval(value)
        expect = int(expect)

        #实例化confighttp方法
        res = ConfigHttp(method, interfaceUrl, value)
        re = res.run()
        #转换返回格式
        re_dict = re.json()
        real = re_dict['errorCode']
        #对接口返回进行断言
        try:
            if real == expect:
                status = 'pass'
            else:
                status = 'fail'
            # 实例化写入方法
            wr = WriteExcle()
            wr.write(int(id), 6, real, status)
        except Exception as msg:
            print(f'报错了:{msg}')
            raise

        #对接口进行断言
        self.assertEqual(real, expect, '测试用例不通过！！！')


    #接口断言
if __name__ == '__main__':
    unittest.main(verbosity=2)